/*
time:20201016 9:02 AM
key:真不知道以前的自己写了什么玩意，回头看觉得异常的复杂。
*/
#include <math.h>
#include <iostream>
using namespace std;

class TreeNode
{
public:
	TreeNode* lc;
	char data;
	TreeNode* rc;
	TreeNode() 
	{
		lc = NULL;
		data = '0';
		rc = NULL;
	}
}
;

void write(TreeNode*head, string &s)
{
	if (head != NULL)
	{
		head->data = s[0];//将字符串的首个字符赋予data
		s.erase(0, 1);//将字符串的首个字符删除
		if (head->data!='#')
		{
			head->lc = new TreeNode;
			write(head->lc, s);
			head->rc = new TreeNode;
			write(head->rc, s);
		}
	}

}

void front_read(TreeNode* head)
{
	if (head != NULL)
	{
		if (head->data != '#')
		{
			cout << head->data;
		}
		front_read(head->lc);
		front_read(head->rc);
	}
}

void middle_read(TreeNode* head)
{
	if (head != NULL)
	{
		middle_read(head->lc);
		if (head->data != '#')
		{
			cout << head->data<<' ';
		}
		middle_read(head->rc);
	}
}

int main()
{
	string s;
	cin >> s;
	TreeNode* root = new TreeNode;
	write(root, s);
	middle_read(root);
		
}


